package com.vj;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CommandLineInterface {
	
	public static void main(String[] args) {
		String lineSeparator = System.getProperty("line.separator");
		CommandLineInterface face = new CommandLineInterface();
		face.run();

		System.exit(0);
	}

	private void run() {
		try {
			InputStreamReader istream = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(istream);
			System.out.println("Go on to run , Continue ? (Y/N)");
			String answer = br.readLine();
			boolean loop = false;
			System.out.println("\n");
			System.out.println("It's My Tool");
			System.out.println("--------------------");
			if ("Y".equalsIgnoreCase(answer) || "Yes".equalsIgnoreCase(answer)) {
				System.out.println(" done.");
				
				do {
					loop = process();
				} while(loop);
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private boolean process() {
		// TODO Auto-generated method stub
		displayMenu();
		int choice = 0;
		choice = getChoice();
		switch(choice) {
		case 0:
			System.out.println("-----------------");
			System.out.println(0);
			do0();
			break;
		case 1:
			System.out.println("-----------------");
			System.out.println(1);
			do1();
			break;
		case 2:
			System.out.println("-----------------");
			System.out.println(2);
			do2();
			break;
		default:
			System.exit(1);
		}
		return true;
	}

	private void do0() {
		// TODO Auto-generated method stub
		System.out.print("Enter your choice: [0,1,2]");
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String s = reader.readLine().trim();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	private void do1() {
		// TODO Auto-generated method stub
		
	}
	private void do2() {
		// TODO Auto-generated method stub
		
	}

	private int getChoice() {
		// TODO Auto-generated method stub
		byte[] input = new byte[40];
		String str ;
		int choice = 0;
		System.out.print(">>> Choose option: ");
		try{
			System.in.read(input);
			str = new String(input).trim();
			choice = Integer.parseInt(str);
		} catch (Exception e){
			System.out.println("Invalid number.");
			input = new byte[40];
		}
		return choice;
	}

	private void displayMenu() {
		// TODO Auto-generated method stub
		
	}

}
